home *** CD-ROM | disk | FTP | other *** search
- #include <dir.h>
- #include <dos.h>
- #include <process.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "listecho.h"
-
- #define MAXNODES 4096
- #define MAXSTRING 256
- #define MAXWIDTH 50
-
- struct singlenode seenbylist[MAXNODES];
- struct doublenode pathlist[MAXNODES];
- struct singlenode prevnode;
- int maxseenby;
- int maxpath;
- int points_ok;
- int smallpaths;
-
- int compsinglenode(struct singlenode *elem1, struct singlenode *elem2) {
- if (elem1->net > elem2->net) return(1);
- if (elem1->net < elem2->net) return(-1);
- if (elem1->node > elem2->node) return(1);
- if (elem1->node < elem2->node) return(-1);
- return(0);
- }
-
- int compdoublenode(struct doublenode *elem1, struct doublenode *elem2) {
- if (elem1->fromnet > elem2->fromnet) return(1);
- if (elem1->fromnet < elem2->fromnet) return(-1);
- if (elem1->fromnode > elem2->fromnode) return(1);
- if (elem1->fromnode < elem2->fromnode) return(-1);
- if (elem1->tonet > elem2->tonet) return(1);
- if (elem1->tonet < elem2->tonet) return(-1);
- if (elem1->tonode > elem2->tonode) return(1);
- if (elem1->tonode < elem2->tonode) return(-1);
- return(0);
- }
-
- void parse_seenby(char *line) {
- char *p;
- char myline[MAXSTRING];
- char *token;
- int mark;
- unsigned int net;
- unsigned int node;
- unsigned int prevnet;
- int i;
-
- strcpy(myline,line);
- p = strstr(myline,"SEEN-BY:");
- p += 8;
- token = strtok(p," ");
- while (token) {
- if (strstr(token,"/")) {
- if (sscanf(token,"%u/%u",&net,&node) == 2)
- prevnet = net;
- }
- else {
- sscanf(token,"%u",&node);
- net = prevnet;
- }
-
- if ((points_ok) || (net < 1000)) {
- if (maxseenby == -1) {
- seenbylist[0].net = net;
- seenbylist[0].node = node;
- maxseenby = 1;
- }
- else {
- mark = 0;
- for (i=0;i<maxseenby;i++) {
- if (seenbylist[i].net == net)
- if (seenbylist[i].node == node) {
- mark = -1;
- break;
- }
- }
- if (!mark) {
- seenbylist[maxseenby].net = net;
- seenbylist[maxseenby].node = node;
- maxseenby++;
- if (maxseenby == MAXNODES) {
- puts("Seen-by list too large!!!");
- exit(1);
- }
- }
- }
- }
- token = strtok(NULL," ");
- }
- }
-
- void parse_path(char *line) {
- char myline[MAXSTRING];
- struct singlenode thisnode;
- struct singlenode node1,
- node2;
- char *p;
- char *token;
- unsigned int currentnet;
- int mark;
- int i;
-
- currentnet = 0;
- strcpy(myline,line);
- p = strstr(myline,"PATH:");
- p += 5;
- token = strtok(p," ");
- while (token) {
- if (strstr(token,"/")) {
- if (sscanf(token,"%u/%u",&thisnode.net,&thisnode.node) == 2)
- currentnet = thisnode.net;
- }
- else {
- sscanf(token,"%u",&thisnode.node);
- thisnode.net = currentnet;
- }
- if (prevnode.net != 0) {
- if (compsinglenode(&prevnode,&thisnode)) {
- if (((!smallpaths) || (prevnode.net != thisnode.net)) &&
- ((points_ok) || ((thisnode.net<1000) && (prevnode.net<1000)))) {
- if (maxpath == -1) {
- if (compsinglenode(&prevnode,&thisnode) == 1) {
- pathlist[0].fromnet = thisnode.net;
- pathlist[0].fromnode = thisnode.node;
- pathlist[0].tonet = prevnode.net;
- pathlist[0].tonode = prevnode.node;
- }
- else {
- pathlist[0].fromnet = prevnode.net;
- pathlist[0].fromnode = prevnode.node;
- pathlist[0].tonet = thisnode.net;
- pathlist[0].tonode = thisnode.node;
- }
- maxpath = 1;
- }
- else {
- if (compsinglenode(&prevnode,&thisnode) == 1) {
- node1.net = thisnode.net;
- node1.node = thisnode.node;
- node2.net = prevnode.net;
- node2.node = prevnode.node;
- }
- else {
- node1.net = prevnode.net;
- node1.node = prevnode.node;
- node2.net = thisnode.net;
- node2.node = thisnode.node;
- }
-
- mark = 0;
- for (i=0;i<maxpath;i++) {
- if (pathlist[i].fromnet == node1.net)
- if (pathlist[i].fromnode == node1.node)
- if (pathlist[i].tonet == node2.net)
- if (pathlist[i].tonode == node2.node) {
- mark = -1;
- break;
- }
- }
- if (!mark) {
- pathlist[maxpath].fromnet = node1.net;
- pathlist[maxpath].fromnode = node1.node;
- pathlist[maxpath].tonet = node2.net;
- pathlist[maxpath].tonode = node2.node;
- maxpath++;
- if (maxpath == MAXNODES) {
- puts("Paths too large!!!");
- exit(1);
- }
- }
- }
- }
- }
- }
- prevnode.net = thisnode.net;
- prevnode.node = thisnode.node;
- token = strtok(NULL," ");
- }
- }
-
- void main(int argc, char *argv[]) {
- char directory[MAXSTRING];
- char path[MAXSTRING];
- char msgpath[MAXSTRING];
- char printline[MAXSTRING];
- char addstring[MAXSTRING];
- FILE *fp;
- FILE *outfile;
- struct ffblk myffblk;
- int i;
- unsigned int prevnet;
- char option;
- char *message;
- char *p,
- *q;
- int index;
- int firstprint;
-
- puts("Echo Lister (C)opywrong 1989 Ronald Bruintjes - The Sorcerer's Cave 2:281/600");
- if ((argc != 2) && (argc != 3)) {
- puts("Usage: listecho <directory> <option>");
- puts("Makes a list of all nodes listed in the SEEN-BY's of that area");
- puts("and a list of all nodes linked by the PATH lines.");
- puts("Option: -v Verbose Pathlinks (all links possible)");
- puts(" -s Small Pathlinks (only between different nets)");
- puts(" -t Tiny Pathlinks (Small, and leave out nets >1000)");
- puts(" This is the default.");
- exit(0);
- }
-
- maxseenby = -1;
- maxpath = -1;
- points_ok = 0;
- smallpaths = -1;
-
- strcpy(directory,argv[1]);
- strcpy(path,directory);
- strcat(path,"*.msg");
-
- option = argv[2][1];
- switch (option) {
- case 's':
- smallpaths = -1;
- points_ok = -1;
- break;
- case 't':
- smallpaths = -1;
- points_ok = 0;
- break;
- case 'v':
- smallpaths = 0;
- points_ok = -1;
- break;
- default:
- smallpaths = -1;
- points_ok = 0;
- }
-
- if (option == 's') smallpaths = -1;
- if (option == 't') {
- smallpaths = -1;
- points_ok = 0;
- }
-
- if (findfirst(path,&myffblk,0)) {
- puts("No messages in that directory");
- exit(1);
- }
-
- do {
- prevnode.net = 0;
- prevnode.node = 0;
-
- strcpy(msgpath,directory);
- strcat(msgpath,myffblk.ff_name);
- puts(msgpath);
- fp = fopen(msgpath,"rb");
- if (fp == NULL) {
- printf("Can't open '%s'.\n",msgpath);
- }
- else {
- message = malloc((int)myffblk.ff_fsize + 2);
- if (message == NULL)
- printf("No memory to load this message! - '%s'.\n",myffblk.ff_name);
- else {
- if (fread(message,1,(int)myffblk.ff_fsize,fp) != (int) myffblk.ff_fsize)
- puts("Error reading message");
- else {
- message[(int)myffblk.ff_fsize + 1] = 0;
- index = 190;
- while (index < myffblk.ff_fsize) {
- p = strstr(message + index,"SEEN-BY:");
- if ((p != NULL) && ((p - message) < myffblk.ff_fsize)) {
- /* SEEN-BY found */
- q = strchr(p,0x0D);
- if ((q != NULL) && ((q - message) < myffblk.ff_fsize)) {
- /* CR found */
- *q = 0;
- index = q - message + 1;
- parse_seenby(p);
- }
- }
- else {
- /* No SEEN-BY found */
- p = strstr(message + index,"PATH:");
- if ((p != NULL) && ((p - message) < myffblk.ff_fsize)) {
- /* PATH found */
- q = strchr(p,0x0D);
- if ((q != NULL) && ((q - message) < myffblk.ff_fsize)) {
- /* CR found */
- *q = 0;
- parse_path(p);
- index = q - message + 1;
- }
- }
- else {
- /*if (p == NULL) puts("No PATH found in msg?");*/
- if ((p-message) < myffblk.ff_fsize) puts("PATH found after end of message!");
- /* No PATH found */
- break;
- }
- }
- }
- }
- free(message);
- }
-
- fclose(fp);
- }
- } while (!findnext(&myffblk));
-
- unlink("OUTPUT");
- outfile = fopen("OUTPUT","wt");
- if (outfile == NULL) {
- puts("Error opening output file - aborting.");
- exit(1);
- }
-
- if (maxseenby>0) {
- qsort(seenbylist,maxseenby,sizeof(struct singlenode),compsinglenode);
- puts("\nList of nodes receiving this echo:");
- prevnet = 0;
- *printline = 0;
- firstprint = -1;
- for (i=0; i<maxseenby; i++) {
- if (prevnet != seenbylist[i].net) {
- sprintf(addstring,"%d/%d ",seenbylist[i].net,seenbylist[i].node);
- prevnet = seenbylist[i].net;
- }
- else
- sprintf(addstring,"%d ",seenbylist[i].node);
- strcat(printline,addstring);
- if (strlen(printline)>MAXWIDTH) {
- if (firstprint) {
- puts(printline);
- fprintf(outfile,"%s\n",printline);
- firstprint = 0;
- }
- else {
- printf("*%s\n",printline);
- fprintf(outfile,"*%s\n",printline);
- }
- prevnet = 0;
- *printline = 0;
- }
- }
- if (firstprint) {
- puts(printline);
- fprintf(outfile,"%s\n",printline);
- }
- else {
- printf("*%s\n",printline);
- fprintf(outfile,"*%s\n",printline);
- }
- }
-
- if (maxpath>0) {
- qsort(pathlist,maxpath,sizeof(struct doublenode),compdoublenode);
- puts("\nList of paths in this echo:");
- *printline = 0;
- firstprint = -1;
- for (i=0; i<maxpath; i++) {
- sprintf(addstring,"%d/%d-%d/%d ",pathlist[i].fromnet,pathlist[i].fromnode,
- pathlist[i].tonet,pathlist[i].tonode);
- strcat(printline,addstring);
- if (strlen(printline)>MAXWIDTH) {
- if (firstprint) {
- puts(printline);
- fprintf(outfile,"%s\n",printline);
- firstprint = 0;
- }
- else {
- printf("*%s\n",printline);
- fprintf(outfile,"*%s\n",printline);
- }
- prevnet = 0;
- *printline = 0;
- }
- }
- if (firstprint) {
- puts(printline);
- fprintf(outfile,"%s\n",printline);
- }
- else {
- printf("*%s\n",printline);
- fprintf(outfile,"*%s\n",printline);
- }
- }
- }
-